package com.celan.year2023.month06.day10;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Celan
 * @description TODO
 */
public class Solution {
    public int[] numSmallerByFrequency(String[] queries, String[] words) {
        List<Integer> wordList = new ArrayList<>();
        for (String s : words) {
            wordList.add(f(s));
        }

        int[] res = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int f = f(queries[i]);
            for (int n : wordList) {
                if (f < n) res[i]++;
            }
        }
        return res;
    }

    private int f(String word) {
        char ch = 'z';
        int cnt = 0;
        for (char c : word.toCharArray()) {
            if (c < ch) {
                ch = c;
                cnt = 1;
            } else if (c == ch) {
                cnt++;
            }
        }
        return cnt;
    }
}
